package my.android.util.r2;


import java.util.Vector;

import android.util.Log;

public class AndroidString extends java.lang.Object
{
	public static final String	DEBUG_TAG	= "AndroidString";

	public static final boolean isEmpty(String source)
	{
		int length = source.length();

		return (length == 0) ? (true) : (false);
	}

	public static Vector<String> readTextLineByLine(String source)
	{
		Vector<String> vector = new Vector<String>();

		int length = source.length();

		StringBuilder string = new StringBuilder();

		int index = 0;

		try
		{
			while ((index != length) && (index < length))
			{
				while ((index != length) && (index < length))
				{
					if ((source.charAt(index) == AndroidGlobal.CR_CARRIAGE_RETURN) || (source.charAt(index) == AndroidGlobal.CR_NEW_LINE))
					{
						index++;

						if ((index == length) || (index > length))
							break;

						continue;
					}

					string.append(source.charAt(index));

					index++;

					if ((source.charAt(index) == AndroidGlobal.CR_CARRIAGE_RETURN) || (source.charAt(index) == AndroidGlobal.CR_NEW_LINE))
					{
						index++;
						break;
					}
				}

				if ((index != length) && (index < length))
				{
					vector.add(string.toString());
					AndroidString.clear(string);

				}
			}

			vector.trimToSize();
		}
		catch (NullPointerException e)
		{
			e.printStackTrace();

			Log.e(DEBUG_TAG, e.getMessage());
		}

		return vector;
	}

	public static void clear(StringBuilder source)
	{
		int length = source.length();

		source.delete(0, length);
	}

	public static void clear(char[] source)
	{
		int length = source.length;

		for (int i = 0; i < length; i++)
		{
			source[i] = '\0';
		}
	}
}
